Add some comments and refactor a few magic numbers out.