Upgraded

Added more logic and resolved a few issues.