first attemp to fix issue#1, not a perfect solution, will improve later