Moved some methods to functions and rearranged tests