Fixed for Tests

Some bugs found by Tests - Refactored
Re-inspected