Changed code order to solver a bug with classes