Modularised it a bit