Major refactor, now it works faster and more correctly

Signed-off-by: eldr4d <nikofinas@gmail.com>