some changes for hopefully better performance