refactor bad code