This code seems a little weird, but I'm not exactly sure how to improve it.