moved plugin unloading to a seperate function

Signed-off-by: Miethpo <miethpomail@yahoo.co.uk>