Refactor tests and source