Small fixes + refactor