switched to insert on duplicate keys update for db storing
added propper phpdoc comments