refactored to use types