reformatted code for better display
more minor editting