Merged and fixed all code errors