fixed segmentation fault, also fixed get register function