Finished code and tests