added protoyping and cleaned up code.