added support for polygon areas, refactored some code