Mid-refactoring. Not sure how this code worked before...