remove unnecessary stuff and implemented missing logic