Added delete function, tided up other functions a bit.
Delete functionality implemented