Refactor tests and increase coverage