This is horrible! Rewrite not to use string operations at all.