formatting and a few bugs fixed