Added helper functions and set up solver