cleaned up code. added a format check, few small things