added registration and fixed bugs