Needing to refactor the code completely