Reordered and grouped things better. Added comments for ease of development and long term maintenance.