This code looks very similar to some code on Stack Overflow. Did you copy it from there? The Stack Overflow license requires attribution, and I'm not sure if it's compatible with the Apache license.