Finished implementation - still needs testing.