This line seems to be repeated at least 3 times... May be a good idea to abstract it into a function?