optimize some unneeded casts (esp. when casting something to string for array access)
fix phpdoc and add typehints to private methods