improve code and tests