fixed linearization for a lot of cases
Some error handling and fixes