Added registration function, still a bit buggy