Minor bug fixes
Minor Refactoring.