added code, may not be the best version