fix and refactor tests