adding factory method pattern
refactor

refactorized common methods into a class