Code improvements and corrections based on feedback by @pjackson28.