credit to ichoes for fixing issue 5