Bug fixes to updated code