Cleaned up code. removed calcaprun() function