enable compilation with aclic
correcting range
fix syntax error
factor out helper function