A bit of rework on the code

This PR contains several changes to the code, it might be a good idea to go over the commits one by one.

Made some minor and some bigger changes. 

Feedback expected and I hope I haven't overstepped my boundaries.