Tidy up the code. Updated notification functionality