Added a singleton pattern

Added a protected singleton pattern to save some resources.