Fixed some issues and redundant code