adding some extra error handling