Inspected code and fixed a few obvious bits