it would be good to move these helper function to outer scope, since that is faster