Rebased fix for issue #40 (doubled javaagent)

This is a consolidated and rebased version of the fix for issue #40 (doubled javaagent)