Added error-handling and more comments