Finished main functionality