Some refactoring and some bug fixes.