Patch 4: Bug fixes