Newly refactored version, with working ajax, correctly commited.