Code cleanup

* subspace key should use strings, not magic ints
* minor cleaanup and reorg of the code

Change-Id: Ia2e33c566a132e55b49a644f8db92f0e4f5c5d3a
Merge "Code cleanup"