Fixed broken code and tests