every thing is functioning , though with dirty loops and brute force, hope to optimize it sometime