Implemented state helper function and fixed binding scope in helper functions