Fix error handling to use state and use try/catch instead of catch
Convert ets interface to new state record