Fixed a bug, moved some code around, made stuff more OOP.