Fixed a few bugs in register script