Added @iroth 's improvements