1) fix for getting wrong height sometimes
1) refactored code