Modified Drew's code slightly