Optimized Code

Fixed some bugs.
Removed unnecessary methods.