added counter() function. improved function error handling. now using rules