fix bugs, stupid rules
refactor the code, remove duplication.