Refactored bug fixes