refactored and cleaned up API