Code cleanup and modernisation