Getting "502 Bad Gateway" error and entry duplication