fix a few bugs with initial implementation