Re-organised the code.