I have no idea if this the correct way to do this or not. At least it works correctly.