Bug fixes with cleanup