cleaned up tests, separated logic a bit more to enable testing