refactored out coordinate computation code