Major refactor and better code