Code update to fix bugs