Add some error handling. Needs improvement still