Refactor and rearrange various methods