Add more comments and exception handling