Add license to end of file, add more error handling