Refactor, clean code and set output dir for bins