Added some error checking in mapper