createOrUpdate method added
some minor refactorings