Add conditions to operations and refactor