Added registration, fixed some bugs