logic error and refactoring