Cleaned up code, added populate access_cabilities