Fixes error with saving to database