tweaked code for timing issues and convenience functions