Refactor based on suggestions made in reddit