improvements to main class so that it runs on PHP>5.3