Improved singleton API and added a test