refactored and add some skeltal code. still bug remained