The function is getting complicated, any refactoring would be best done outside of 'space_toolsystem_common'.