added formatting and fixed some bugs