More code tidying, added registration functionality.