move save_user method into lib file