Allow complex, custom masks to be specified. Caret positioning code refacor.