refactoring sprite logic