refactor and make it also work on centos 6
refactor things for >2.7