Moved capabilities array generation code into seperate function