some refactoring to make doubles easier