added option for action selection and cleaned code