Added if spec==null statements around the code and fixed bug that
returned null in improve()