Frame buffer and some refactoring