Completed code and tests