Cleaned version  -- got rid of extraneous functions