add frame switching logic