@xchrdw 
consider putting both blocks of the if-else into separate function with meaningful names. I have no idea what the difference it and when there are invalid up-pointers passed...