added new rules and better error handling