Reorded function definitions
Simplified the API