Move tests to separate file
Clarify some logic