Finished main implementation