CLEANED UP CODE