keep formatting and cleaning up code, adding try clauses around necessary places