Refactoring and added generator tests