Updated to fix bugs