split client script onto options and common part, refactor