moved solve logic to function