Updated with important comments.
Added charset to content-type header.
Generating all needed keys. Dirty but it works :)