Final code and tests