credit to ichoes for fixing issue 6