Removed environment dependancy from algorithm
minor bug  fixes