Refactor and prepare some tests