implemented solve function