Finished main implementation.