Save class done

the code is a bit messy, check the comment on the top of the page.