Renamed functions and added some helper functions