add error calc to PLA, refactor code