Code cleanup to use constants; adds comments to define code sections