Refactoring. Fixed the Frame Error. Still have memory issue