implemneting singleton, cleaning code, fixing bugs