refactored code. working towards implementing more rules.