Fixed using the wrong array key [0]. And improved code.