added some documnetation and logic changes