Improve saving code and functionality