fixed index and remove empty elements