fix segfaults

fixed segfault on my work account, will merge it via my home account (@deanmao)