Merged with Sams's updates
merged sam and mj code