Fixed some bugs noticed when porting to new device