Few more minor changes to prevent duty from being out of expected range.  Some other code cleanup for readability.