some bug fixes related to the rearranging and refactoring.