Some issues fixed and more commented code