some code re-factored; done issue #150