fixed some inner logic