Added most of the needed functionality for #6.