Added comments and some error handling.