updated code and tests