Fixed some bugs, now stores correctly