Improve the thing a bit and refactor the if's