Renamed functions and modularized