Modified to properly trim input data and send cookies properly