implemented all rules, but some bug fixes are necessary