Some code refactorig and other random stuff