Bug Fixes and code tweaks