Add dependencies and refactor code