Improved API.text() code

Made the align code more efficient, and improved the example code.