Refactor and tweaks