Working atlas code, there is probably a couple of things left to fix but it works for simple stuff.