Added support for autolayout and refactored internal code.

Just creating a pull request on our end for this.
The spelling gods are angry with you.