Fixed bugs and integrated with Craig's stuff