Added building rules, refactoring.