Updated code and tests