Test and code refactoring