Added some error preventions