Merged duncan's and lizzy's code