Fixed and added missing code