Added some extra formatting and error checks