Towards a Flexible Middleware for Context-aware Pervasive and Wearable Systems