renamed some variables
fixed a bug that led to faulty behaviour