Modified to accomodate unit testing.