refactored runtime code