Re-working of code