Cleanup and fixes for habitat calculations