Finished the main functionality