Refactoring done. First impression is that its looks good. Need to test
it all out again.