Additional bug fixes and improved handing for touch devices. Code refactoring