Edited to use more numpy functions