Tidied up solver code