Code tested and revised

Tested, revised and further documented