Bug fixes and internal changes