some cleaning in code, added comments