Better singleton implementation and main class refactor