Some refactoring + using regex to validate http requests.