Minor Bug Fixes
Refactoring.