Added regex stuff, and also optimised the code a bit