fixed bugs from last commit -- had not tested things properly