applied fix suggestions by vecna and hellais