fix several bugs, minor style changes