fix some bugs, 80-column violations, improved plan