cleaned code and reactivated diagnostic plotting