Fix for incorrect height calculation.

- A complete refactoring
- Add RTL support
- Minor fixes