Have to make this configurable.
Make this function neater.
Might fix a bug.