better code formatting and comments inserted