refact and remove unused code