Major code cleanup. It seems everything is still working ;)