add some more error code checks and returns