Cleaning up the code, trying to solve issue #2.