Refactored, plus added polygon test