fixed a bug in register function