refactor crappy code