added some optimazations