Refactor the singleton functionality into a trait