Modularise this, will finish this later