add helper functions and comment