Fixed some NPEs, revamped plugin