Cleaned up. Need to add helpful comments and generalize.