refiled some code and clarifications