clean code and fix tests