Some more cleaning and commenting. Bugfixing in pagination. Should work now.