Fixed the nans caused by array alignment. Fixed other stuff. pha_err is still wrong. WIP