refactored attach_xvfb method