Try to implement this code. It still should work with the current version too.