fixed up expand function