You might consider organizing this code with a case statement, rather than a bunch of if's.