solve function! (and slightly improved print)