used Andrew Nicols solution