fixed security rule hanlding & code cleanup