functionality for 1st version is done. needs only improving style and refactoring a little