changed text to varchar
removed unnecessary typecasts, updated comments