bugs fix and better organization