added some comments for clarity. cleaned a bit layout