Refactoring a lot. From controller to models
Bugs fixed