Assignment 4 submission version, completely reworked.