Added helper functions from previous code