some cleanup of types and reusing code