minor bug fixes, logic cleanup