added foreground boolean

Fixing issue #79 although this way is not totally reliable it's better then nothing