Refactor and update to tf2