Initial refactoring. Need to fix the different ghci versions