Lots of refactoring and make it easier to work with

The code is still not as good organized, but it is way better than it was before.