Added null pointer checks and fixed sequence name picking