Documentation added and code cleanup