Configure tests, refactor code