Huge chunk of code

mainly dimension stuff