move loop to function
updated some style