Added some test and refactored some stuff