Mostly done, needs huge refactoring