Make procedural function more generic