Updated code, works better now.