more compact code, slight modifications to work with clang