Fixed some bugs and added #pri code