added comment with reference and cleaned up code structure