various bug fixes for typeos and logic errors