Fix RHEL/CentOS issues && refactor code