Slight refactoring. Added singletons where necessary.