Massive code cleanup, added user-agent