Added some error checks and some renaming