Refactored some more
Splitted out and added some more unit tests