Move functions to more appropriate files
Add compute_count