improve helper function