Refactor of spaces controller