some refactor
split main into 2 submethods
have print buit-in redirect to stdout