initial version
refactered code