Restructured code, added pointer support