refactored to use types. Unfortunately lost ghlib for I have idea reason. Can't recover. Pushing first