Refactored the whole application