Refactor and add rollback