Big refactoring. Very powerful api created!