changed most parts of code, marked as '#warnign @Mattias' by christof