Refactoring to improve spatial API