Simplified some code
Simplified API and marked some functions as inline