What's up with maxline? What is this var saving? I couldn't tell from the code. Also, what's that magic number 8 here in this line?
Maybe add a comment so that it's easier to understand what you're using maxline for.