Fixed broken space behaviour

document.documentElement returned <html> element and lead to incorrect
behaviour when space was pressed.

Also rounding errors prevented detection of scroll to the end of page
sometimes.