Fixed #236 Back to the original implementation. Added some security constraint that helped to find the problem.