fixed output problems and switched to a generic function for delivery