Added text functionality and cleaned up code