quick and dirty refactor

Just a few things i felt would make the code a bit more understandable without really digging too much