Make code cleaner, change api to be more transparent