Refactor to have better code organized