refactoring kasheys code