Split functionality into several smaller classes

* improve performance by using arrays of integers as coordinates