This function is the bottleneck of the app when under load. Consider refactoring/optimizing.