fixed bug, improved speed