Imporvements and refactorings