Updated to fix various bugs

Updated to fix various bugs