Finished main funcitonaility