Combined my code with Andrew's