Added comments and exception handling