Added support for autolayout and refactored internal code.

Just creating a pull request on our end for this.