Refactored and cleaned up code for coordinator