Cleaned up code (with the help of a few additional imports).