Implemented a proper ThreadedAPT class

This make the code cleaner because all the thread stuff is hidden inside the new class.
The new class also implement a callback system to inform the main thread when the long operation is finished