edit code for better viewing and comments for better trouble-shooting