Fix the buggy previous version, works fine now.
Bugs fixed