consolidating helper code