Major fail wwhile trying to rewrite some code.