Added some documentation, added error handling