PR #47 - merged version

Modified version of PR #47 (merged the stuff, remov2ed obsolete commits)