doubled speed by caching square/coords transformations