Robustifying: handling window scroll, resize and other events. Code-cleanup

Hello,

did some cleanup to this lib. Please consider pulling changes.

Thnx